/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Visoes;

import Conexao.ClienteDAO;
import Conexao.Conexao;
import Controle.ControleCliente;
import java.util.logging.Logger;
import java.util.logging.Level;
import javax.swing.JComboBox;
import javax.swing.JTextField;


/**
 *
 * @author Jordyson
 */
public class TelaCadastroCliente extends javax.swing.JDialog {

    /**
     * Creates new form TelaCadastroCliente
     */
    public TelaCadastroCliente(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        tId = new javax.swing.JTextField();
        tTelefone2 = new javax.swing.JTextField();
        tNome = new javax.swing.JTextField();
        tCpf = new javax.swing.JTextField();
        tEmail = new javax.swing.JTextField();
        tCidade = new javax.swing.JTextField();
        tTelefone1 = new javax.swing.JTextField();
        cbxUf = new javax.swing.JComboBox();
        btSalvar = new javax.swing.JButton();
        btLimpar = new javax.swing.JButton();
        btCancelar = new javax.swing.JButton();
        btNovo = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Formulário de Cadastro");
        setResizable(false);
        getContentPane().setLayout(null);

        jLabel1.setText("Celular");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(13, 260, 40, 20);

        jLabel2.setText("ID");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(21, 24, 40, 14);

        jLabel3.setText("CPF");
        getContentPane().add(jLabel3);
        jLabel3.setBounds(19, 100, 30, 20);

        jLabel4.setText("Nome");
        getContentPane().add(jLabel4);
        jLabel4.setBounds(17, 60, 40, 20);

        jLabel5.setText("E-mail");
        getContentPane().add(jLabel5);
        jLabel5.setBounds(18, 140, 40, 20);

        jLabel6.setText("Telefone");
        getContentPane().add(jLabel6);
        jLabel6.setBounds(12, 220, 60, 20);

        jLabel7.setText("Cidade");
        getContentPane().add(jLabel7);
        jLabel7.setBounds(13, 180, 60, 20);

        jLabel8.setText("Uf");
        getContentPane().add(jLabel8);
        jLabel8.setBounds(380, 180, 40, 20);

        tId.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tIdActionPerformed(evt);
            }
        });
        getContentPane().add(tId);
        tId.setBounds(70, 20, 180, 30);

        tTelefone2.setEnabled(false);
        getContentPane().add(tTelefone2);
        tTelefone2.setBounds(70, 260, 170, 30);

        tNome.setEnabled(false);
        getContentPane().add(tNome);
        tNome.setBounds(70, 60, 350, 30);

        tCpf.setEnabled(false);
        getContentPane().add(tCpf);
        tCpf.setBounds(70, 100, 260, 30);

        tEmail.setEnabled(false);
        tEmail.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tEmailActionPerformed(evt);
            }
        });
        getContentPane().add(tEmail);
        tEmail.setBounds(70, 140, 260, 30);

        tCidade.setEnabled(false);
        getContentPane().add(tCidade);
        tCidade.setBounds(70, 180, 240, 30);

        tTelefone1.setEnabled(false);
        getContentPane().add(tTelefone1);
        tTelefone1.setBounds(70, 220, 170, 30);

        cbxUf.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "         ", "AC", "AL", "AP", "AM", "BA", "CE", "DF", "ES", "GO", "MA", "MT", "MS", "MG", "PA", "PB", "PR", "PE", "PI", "RJ", "RN", "RS", "RO", "RR", "SC", "SP", "SE", "TO" }));
        cbxUf.setEnabled(false);
        getContentPane().add(cbxUf);
        cbxUf.setBounds(430, 180, 160, 30);

        btSalvar.setText("Salvar");
        btSalvar.setEnabled(false);
        btSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSalvarActionPerformed(evt);
            }
        });
        getContentPane().add(btSalvar);
        btSalvar.setBounds(370, 310, 80, 40);

        btLimpar.setText("Limpar");
        btLimpar.setEnabled(false);
        btLimpar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btLimparActionPerformed(evt);
            }
        });
        getContentPane().add(btLimpar);
        btLimpar.setBounds(470, 310, 80, 40);

        btCancelar.setText("Cancelar");
        btCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCancelarActionPerformed(evt);
            }
        });
        getContentPane().add(btCancelar);
        btCancelar.setBounds(570, 310, 90, 40);

        btNovo.setText("Novo");
        btNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btNovoActionPerformed(evt);
            }
        });
        getContentPane().add(btNovo);
        btNovo.setBounds(270, 310, 80, 40);

        setSize(new java.awt.Dimension(723, 422));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void tIdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tIdActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tIdActionPerformed

    private void tEmailActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tEmailActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tEmailActionPerformed

    private void btNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btNovoActionPerformed
        Novo();
    }//GEN-LAST:event_btNovoActionPerformed

    private void btLimparActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btLimparActionPerformed
        LimparCampos();
    }//GEN-LAST:event_btLimparActionPerformed

    private void btCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelarActionPerformed
        this.dispose();
    }//GEN-LAST:event_btCancelarActionPerformed

    private void btSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSalvarActionPerformed
        try{
            ControleCliente controlCli = new ControleCliente();
            controlCli.cadastrarCliente(this);
            this.LimparCampos();
        }catch(Exception ex){
            Logger.getLogger(Conexao.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btSalvarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TelaCadastroCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TelaCadastroCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TelaCadastroCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TelaCadastroCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                TelaCadastroCliente dialog = new TelaCadastroCliente(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btCancelar;
    private javax.swing.JButton btLimpar;
    private javax.swing.JButton btNovo;
    private javax.swing.JButton btSalvar;
    private javax.swing.JComboBox cbxUf;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JTextField tCidade;
    private javax.swing.JTextField tCpf;
    private javax.swing.JTextField tEmail;
    private javax.swing.JTextField tId;
    private javax.swing.JTextField tNome;
    private javax.swing.JTextField tTelefone1;
    private javax.swing.JTextField tTelefone2;
    // End of variables declaration//GEN-END:variables
  public void Novo(){
        tId.setEnabled(false);
        tNome.setEnabled(true);
        tCpf.setEnabled(true);
        tEmail.setEnabled(true);
        tTelefone1.setEnabled(true);
        tTelefone2.setEnabled(true);
        tCidade.setEnabled(true);
        cbxUf.setEnabled(true);
        cbxUf.setEnabled(true);
        btSalvar.setEnabled(true);
        btLimpar.setEnabled(true);
        btNovo.setEnabled(false);
        
        
    }
   
   private void LimparCampos() {
        this.tId.setText("");
        this.tNome.setText("");
        this.tCpf.setText("");
        this.tEmail.setText("");
        this.tCidade.setText("");
        this.cbxUf.setSelectedIndex(0);
        this.tTelefone1.setText("");
        this.tTelefone2.setText("");
    }

    public javax.swing.JTextField gettNome() {
        return tNome;
    }

    public void settNome(javax.swing.JTextField tNome) {
        this.tNome = tNome;
    }

    public javax.swing.JTextField gettCpf() {
        return tCpf;
    }

    public void settCpf(javax.swing.JTextField tCpf) {
        this.tCpf = tCpf;
    }

    public JTextField gettId() {
       return tId;
    }

    public void settId(JTextField tId) {
        this.tId = tId;
    }

    public JTextField gettEmail() {
        return tEmail;
    }
    
    public void settEmail(JTextField tEmail){
        this.tEmail = tEmail;
    }
    
     public JTextField gettCidade() {
       return tCidade;
    }

    public void settCidade(JTextField tCidade) {
        this.tCidade = tCidade;
    }
    
     public JComboBox getcbxUf() {
       return cbxUf;
    }

    public void setcbxUf(JComboBox cbxUf) {
        this.cbxUf = cbxUf;
    }
    
     public JTextField gettTelefone1() {
       return tTelefone1;
    }

    public void settTelefone1(JTextField tTelefone1) {
        this.tTelefone1 = tTelefone1;
    }
    
     public JTextField gettTelefone2() {
       return tTelefone2;
    }

    public void settTelefone2(JTextField tTelefone2) {
        this.tTelefone2 = tTelefone2;
    }

}
